package br.ufla.pgcc.oomeasures.plugin.views;

import java.util.List;

import javax.swing.JFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

import br.ufla.pgcc.oomeasures.ItemMeasured;


@SuppressWarnings("serial")
public class PopPieChartView extends JFrame {

	public PopPieChartView(ItemMeasured itemMeasured) {
		
		double pieRatio = 0.0;
		
		System.out.println("ESTOU NO PieChartView \n\n");//RODRIGO
		DefaultPieDataset PieChartDataset = new DefaultPieDataset();
		String projectName = "";
		
		if (itemMeasured != null) {
			System.out.println("No loop do itemMeasured");//RODRIGO PROBLEMA DE MEMÒRIA
			List<ItemMeasured> items = itemMeasured.getChildren();
			projectName = itemMeasured.getName();
			
			for (ItemMeasured item : items) {
				pieRatio += item.getValue();
			}

			for (ItemMeasured item : items) {
				PieChartDataset.setValue(item.getName(), item.getValue() / pieRatio);
				System.out.println(item.getValue() + projectName + item.getName());//RODRIGO
			}
			
			JFreeChart grafico = ChartFactory.createPieChart("Measures of the project " + projectName,
					PieChartDataset,
					true,
					true,
					false);
			
			
			this.add(new ChartPanel(grafico));
			this.pack();
			

		}
		
	}

	public void setPieVisible(ItemMeasured itemMeasured) {
		
		new PopPieChartView(itemMeasured).setVisible(true);
		
	}


}
